#pragma once

#include <QThread>
#include <QString>
#include <memory>
#include "Machine.h"

class Worker : public QThread
{
    Q_OBJECT

public:
    Worker(const QString& algorithmPath, int stopTimeout, QObject* parent = 0);

public slots:
	void Stop(bool gentle = true);

signals:
    void success();
    void failure();

private:
	virtual void run();

private:
    void ConstructChannels(const StringMapMap& channels);
    bool EstablishConnections();

private:
    QString     _algorithmPath;
    int         _stopTimeout;

private:
    DraftPtr    _draft;
    MachinePtr  _machine;
    bool        _stop;
    Machine::ChannelMap  _channels;
};

typedef std::tr1::shared_ptr<Worker> WorkerPtr;
